package com.sdutcm.Controller;

import com.sdutcm.Domain.ClassRoom;
import com.sdutcm.Service.ClassService;
import com.sdutcm.Service.ServiceImpl.ClassServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/*
 *@Author Yan
 *@Create 2019-08-21 11:36
 */
@Controller
public class ClassController {

    @Autowired
    private ClassServiceImpl classService;

    @ResponseBody
    @PostMapping(value = "/findClassData")
    public Map<String, List<String>> classfind(ClassRoom classRoom) throws Exception {
        List<String> classfind = classService.classfind(classRoom);
        Map<String,List<String>> map = new HashMap<>();
        List<String> yi = new ArrayList<>();
        List<String> er = new ArrayList<>();
        List<String> san = new ArrayList<>();
        List<String> si = new ArrayList<>();
        List<String> wu = new ArrayList<>();
        List<String> liu = new ArrayList<>();
        List<String> qi = new ArrayList<>();
        List<String> ba = new ArrayList<>();
        for (String list:classfind){
            switch (list.substring(0,2)){
                case "11":{
                    yi.add(list);
                    break;
                }
                case "12":{
                    er.add(list);
                    break;
                }
                case "13":{
                    san.add(list);
                    break;
                }
                case "14":{
                    si.add(list);
                    break;
                }
                case "21":{
                    wu.add(list);
                    break;
                }
                case "22":{
                    liu.add(list);
                    break;
                }
                case "23":{
                    qi.add(list);
                    break;
                }
                case "24":{
                    ba.add(list);
                    break;
                }
            }
        }
        map.put("yi",yi);
        map.put("er",er);
        map.put("san",san);
        map.put("si",si);
        map.put("wu",wu);
        map.put("liu",liu);
        map.put("qi",qi);
        map.put("ba",ba);
        return map;
    }
}
